﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

namespace ResearchId.Validation
{
    public partial class StudentInfo : System.Web.UI.Page
    {
        private const int _groupId = 8;
        private const ClaimEnum _claimId_studentId = ClaimEnum.StudentId;
        private const string _studentId_datatype = "System.String";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }
        }
        private void LoadData()
        {
            Group myGroup = Group.GetGroup(_groupId);
            foreach (GroupClaim myClaim in myGroup.GroupClaims)
            {
                IndividualClaim myIndividualClaim = IndividualClaim.GetIndividualClaim(
                    (ClaimEnum)myClaim.ClaimId
                    , Individual.GetIndividual(Page.User.Identity.Name).IndividualId);
                if (myIndividualClaim != null)
                {
                    switch ((ClaimEnum)myIndividualClaim.ClaimId)
                    {
                        case _claimId_studentId:
                           tbStudentId.Text= myIndividualClaim.Value;
                            break;
                    }
                }
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {            
            string UserName = Page.User.Identity.Name;
            Individual i = Individual.GetIndividual(UserName);
            IndividualClaim.CreateIndividualClaim(
                i.IndividualId
                , _claimId_studentId
                , tbStudentId.Text
                , _studentId_datatype);
        }

        protected void btnBack_Click(object sender, EventArgs e)
        {
            Response.Redirect("..\\default.aspx");
        }
    }
}
